'use strict';
// Copyright 2014 Blueant Inc. All Rights Reserved.

/**
 * @fileoverview vip等级
 * @author sundbcn@gmail.com (sun debing)
 */

var moment = require('moment');
var modelUtil = require('../util/modelUtil');
var constantUtil = require('../util/constantUtil');
var mongoConnector = require('../libs/mongodb/mongoConnector');
/* jshint unused:false */
var vipSchema = require('../schemas/vipSchema');
var Vip = mongoConnector().model('Vip');

/**
 * 根据role_id获取model
 * @return {[type]} [description]
 */
module.exports.getByRoleId = function (role_id, cb) {
    modelUtil.getByRoleId(Vip, role_id, function (err, vip_model) {
        if (!!err) {
            console.error(err);
            return cb(err);
        }
        _resetVip(vip_model);
        cb(null, vip_model);
    });
};

/**
 * 重置超值礼包
 * @return {[type]} [description]
 */
var _resetVip = function (vip_model) {
    if (moment(vip_model.getLastRefreshTime()) <= moment().startOf('week')) {
        vip_model.refresh();
    }
};
